#include "repairratewidget.h"
#include "ui_repairratewidget.h"
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <QMessageBox>

RepairRateWidget::RepairRateWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RepairRateWidget)
{
    ui->setupUi(this);
    initWindow();
}

RepairRateWidget::~RepairRateWidget()
{
    delete ui;
}

void RepairRateWidget::setRepairId(int id)
{
    this->repair_id = id;
}

/**
 * @brief 维修评价
 */
void RepairRateWidget::on_btn_save_clicked()
{
    QString rate = ui->edit_rate->toPlainText();
    qDebug() << "评价信息：" << rate
             << "所评价的记录id：" << this->repair_id;
    QSqlQuery query;
    query.prepare("UPDATE repair_apply SET repair_process='已评价', repair_rate = :rate WHERE id = :id");
    query.bindValue(":rate", rate);
    query.bindValue(":id", this->repair_id);
    if (!query.exec())
    {
        qDebug() << query.lastError();
    }
    else
    {
        QMessageBox::information(this, tr("提示"), tr("更新成功"));
    }
    emit closeAndFlush();
}

/**
 * @brief 初始化窗体
 */
void RepairRateWidget::initWindow()
{
    this->setWindowTitle("维修评价");
}
